package com.example.demo.config;

import dev.openfeature.contrib.providers.flagd.FlagdProvider;
import dev.openfeature.sdk.OpenFeatureAPI;
import dev.openfeature.sdk.exceptions.OpenFeatureError;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class OpenFeatureBeans {

  @Bean
  public OpenFeatureAPI OpenFeatureAPI() {
    final OpenFeatureAPI openFeatureAPI = OpenFeatureAPI.getInstance();
    try {
      openFeatureAPI.setProviderAndWait(new FlagdProvider());
    } catch (OpenFeatureError e) {
      throw new RuntimeException("Failed to set OpenFeature provider", e);
    }
    return openFeatureAPI;
  }

}
